package com.chance.cc.crawler.prod.command.schedule.news.zhihu;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.meta.core.bean.crawler.CrawlerDomainKeys;
import com.chance.cc.crawler.prod.command.meta.CrawlerDomainKeywordCommand;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;

/**
 * @author bx
 * @date 2020/12/15 0015 13:26
 */
@Data
@AllArgsConstructor
public class ZHKeywordImport {

    public static void main(String[] args) throws IOException {
//        String courseFile = "D:\\chance\\gitspace\\chance-crawler-development\\crawler-scripts-command-prod\\src\\main\\java\\com\\chance\\cc\\crawler\\prod\\command\\schedule\\news\\zhihu\\zh_kw.txt";
        String courseFile = "crawler-scripts-command-prod/src/main/java/com/chance/cc/crawler/prod/command/schedule/news/zhihu/zh_kw.txt";
        List<String> kwLines = IOUtils.readLines(new FileInputStream(courseFile), Charset.forName("UTF-8"));
        CrawlerDomainKeywordCommand crawlerDomainKeywordCommand =
                new CrawlerDomainKeywordCommand("192.168.1.217",9599);

        for (String kwLine : kwLines) {
            if (kwLine.startsWith("#")){
                continue;
            }
            String[] dyKeyword = kwLine.split("\t");


            CrawlerDomainKeys crawlerDomainKeys = new CrawlerDomainKeys();
            crawlerDomainKeys.setDomain("zhihu");
            crawlerDomainKeys.setStatus(0);
            crawlerDomainKeys.setKeyword(kwLine.trim());
            crawlerDomainKeys.setSite("search");
            crawlerDomainKeywordCommand.addOrUpdateKeys(crawlerDomainKeys);
//            crawlerDomainKeywordCommand.delKeys(crawlerDomainKeys);
            System.out.println(JSON.toJSONString(crawlerDomainKeys));
        }

    }
}
